# @Time    : 2024/12/31 11:19
# @Author  : Zhang Yihao
import os


def seek_start():
    """
    相对于开头（文件起始位置）进行偏移
    :return:
    """
    file = open("file1", mode="r+",encoding='utf-8')
    file.seek(6,os.SEEK_SET)
    text=file.read(5)# 从文件开头偏移5个字符
    print(text)
    file.close()

def seek_end():
    """
    相对于开头（文件起始位置）进行偏移
    :return:
    """
    file = open("file1", mode="r+",encoding='utf-8')
    file.seek(0, os.SEEK_END)# 从文件末尾
    text=file.read(5)# 从文件开头偏移5个字符
    print(text)
    file.close()

def copy():
    """
    复制文件
    :return:
    """
    file1 = open("file1", mode="rb+")
    file2 = open("file2_copy", mode="wb")
    b=file1.read()
    file2.write(b)
    file1.close()
    file2.close()

# 修改文件
def modify_movie():
    file1=open('photo.jpg',mode='rb+')
    file1.seek(10,os.SEEK_SET)
    b=file1.read(1)
    inverted_b=bytes(~b[0]&0xFF)
    file1.seek(10,os.SEEK_SET)
    file1.write(inverted_b)
    file1.close()

if __name__ == '__main__':
    # seek_start()
    # seek_end()
    modify_movie()